package edu.mobbuzz.web.model;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry5.OptionGroupModel;
import org.apache.tapestry5.OptionModel;
import org.apache.tapestry5.SelectModel;
import org.apache.tapestry5.SelectModelVisitor;
import org.apache.tapestry5.internal.OptionModelImpl;
import org.apache.tapestry5.internal.SelectModelImpl;

public class StatusSelectionModel implements SelectModel{

	private List<String> statusList;
	
	public StatusSelectionModel(List<String> statusList){
		this.statusList = statusList;
	}
	public List<OptionGroupModel> getOptionGroups() {
		return getSelectModel().getOptionGroups();
	}

	public List<OptionModel> getOptions() {
		return getSelectModel().getOptions();
	}

	public void visit(SelectModelVisitor visitor) {
		getSelectModel().visit(visitor);

	}
	
	public SelectModel getSelectModel() {
		List<OptionModel> optionModelList = new ArrayList<OptionModel>();
		
		
		for(String status: statusList) {			
			if(status.equals("user")){
				optionModelList.add(new OptionModelImpl(status,new Integer(0)));
			}else if (status.equals("administrator")) {
				optionModelList.add(new OptionModelImpl(status,new Integer(1)));
			}
			
		} 
		return new SelectModelImpl(null, optionModelList); 
	}

}
